home *** CD-ROM | disk | FTP | other *** search
/ AI Game Programming Wisdom / AIGameProgrammingWisdom.iso / SourceCode / 10 Scripting / 01 Berger / SmartPtr.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2001-10-09  |  337 b   |  35 lines

  1. #include <assert.h>
  2.  
  3. #include "SmartPtr.H"
  4.  
  5.  
  6. RefCount::RefCount()
  7.   : m_refs( 0 )
  8. {
  9. }
  10.  
  11.  
  12. RefCount::~RefCount()
  13. {
  14.   assert( m_refs == 0 );
  15. }
  16.  
  17.  
  18. void
  19. RefCount::AddReference()
  20. {
  21.   ++m_refs;
  22. }
  23.  
  24.  
  25. void
  26. RefCount::RemoveReference()
  27. {
  28.   assert( m_refs != 0 );
  29.  
  30.   --m_refs;
  31.  
  32.   if ( m_refs == 0 )
  33.     delete this;
  34. }
  35.